package com.pelli.imarket.client.panels;

import com.extjs.gxt.ui.client.Style.ButtonArrowAlign;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.EventType;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.button.ButtonBar;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.google.gwt.user.client.ui.RootPanel;
import com.pelli.imarket.client.Imarket;
import com.pelli.imarket.client.panels.listeners.LoginListener;

public class LoginPanel {

	
	private TextField<String> txtUsername ;
	public TextField<String> getTxtUsername() {
		return txtUsername;
	}
	public TextField<String> getTxtPassword() {
		return txtPassword;
	}
	private TextField<String> txtPassword ;
	public void init() {
		RootPanel rootPanel = Imarket.getRootPanel();
//		rootPanel.setHeight("720");
//		rootPanel.setWidth("1280");
		LayoutContainer layoutContainer = new LayoutContainer();
		layoutContainer.setLayout(new BorderLayout());
		
		ContentPanel center = new ContentPanel();
		center.setHeading("Login");
		
		center.setBorders(false);
		center.setCollapsible(true);
		center.setLayout(new FormLayout());
		BorderLayoutData bldCenter =new BorderLayoutData(LayoutRegion.CENTER,400);
		bldCenter.setMargins(new Margins(30,400,380,400));
		
		txtUsername = new TextField();
		FormData fdTxtUsername = new FormData("100%");
		fdTxtUsername.setMargins(new Margins(5, 5, 2, 0));
		center.add(txtUsername, fdTxtUsername);
		txtUsername.setFieldLabel("Username");
		
		txtPassword = new TextField();
		txtPassword.setPassword(true);
		FormData fdTxtPassword = new FormData("100%");
		fdTxtPassword.setMargins(new Margins(5, 5, 5, 0));
		center.add(txtPassword, fdTxtPassword);
		txtPassword.setFieldLabel("Password");
		
		ButtonBar buttonBar = new ButtonBar();
		
		com.extjs.gxt.ui.client.widget.button.Button btnLogin = new com.extjs.gxt.ui.client.widget.button.Button("Login");
		btnLogin.setType("submit");
		btnLogin.setArrowAlign(ButtonArrowAlign.BOTTOM);
		btnLogin.addSelectionListener(new LoginListener(this));
		
		buttonBar.add(btnLogin);
		FormData fd_buttonBar = new FormData("100%");
		fd_buttonBar.setMargins(new Margins(10, 100, 10, 100));
		
		com.extjs.gxt.ui.client.widget.button.Button btnAnnulla = new com.extjs.gxt.ui.client.widget.button.Button("Annulla");
		btnAnnulla.setType("reset");
		btnAnnulla.addSelectionListener(new SelectionListener<ButtonEvent>() {
			
			@Override
			public void componentSelected(ButtonEvent ce) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void handleEvent(ButtonEvent e) {
				// TODO Auto-generated method stub
				super.handleEvent(e);
				txtUsername.clear();
				txtPassword.clear();
				
			}
			
			
			
		});
		buttonBar.add(btnAnnulla);
		center.add(buttonBar, fd_buttonBar);
		layoutContainer.add(center,bldCenter );
		
		
		rootPanel.add(layoutContainer);		
	}
	
	

}
